package com.szaupd.utils;

import java.time.LocalDate;

public class DateUtils {

    /**
     * 日期+1
     *
     * @param today
     * @return
     */
    public static int addOneDay(int today) {
        int dayOfMonth = today % 100;
        int month = today / 100 % 100;
        int year = today / 100 / 100;
        LocalDate date = LocalDate.of(year, month, dayOfMonth);
        LocalDate tDate = date.plusDays(1);
        int year1 = tDate.getYear();
        int month1 = tDate.getMonthValue();
        int dayOfMonth1 = tDate.getDayOfMonth();
        String day = year1 + (month1 < 10 ? "0" : "") + month1 + (dayOfMonth1 < 10 ? "0" : "") + dayOfMonth1;
        return Integer.valueOf(day);
    }

    public static int getToday(){
        LocalDate date = LocalDate.now();
        int year = date.getYear();
        int month = date.getMonthValue();
        int dayOfMonth = date.getDayOfMonth();
        String day = year + (month < 10 ? "0" : "") + month + (dayOfMonth < 10 ? "0" : "") + dayOfMonth;
        return Integer.valueOf(day);
    }
    public static int getYesterday(){
        LocalDate date = LocalDate.now();
        date = date.minusDays(1);
        int year = date.getYear();
        int month = date.getMonthValue();
        int dayOfMonth = date.getDayOfMonth();
        String day = year + (month < 10 ? "0" : "") + month + (dayOfMonth < 10 ? "0" : "") + dayOfMonth;
        return Integer.valueOf(day);
    }

    public static void main(String[] args) {
        int yesterday = getYesterday();
        System.out.println("yesterday = " + yesterday);
    }
}
